﻿using System;
using MugenMvvmToolkit.Interfaces;

namespace MugenMvvmToolkitTest.TestInfrastructure
{
    public class TestStateProvider : IEntityStateProvider
    {
        #region Properties

        public Func<object, object> SaveDelegate { get; set; }

        public Func<object, object> ApplyDelegate { get; set; }

        public Func<object, object> CancelDelegate { get; set; }

        public Func<object, string, bool> HasChangesPropDelegate { get; set; }

        public Func<object, bool> HasChangesDelegate { get; set; }

        #endregion

        #region Implementation of IEntityStateProvider

        /// <summary>
        ///     Gets a value indicating whether the provider supports changed detection.
        /// </summary>
        public bool IsSupportChangeDetection { get; set; }

        /// <summary>
        ///     Saves a state of entity.
        /// </summary>
        /// <param name="entity">The specified entity.</param>
        /// <returns>An instance of object.</returns>
        object IEntityStateProvider.Save(object entity)
        {
            return SaveDelegate(entity);
        }

        /// <summary>
        ///     Applies a state of entity.
        /// </summary>
        /// <param name="entity">The specified entity.</param>
        /// <returns>An instance of object.</returns>
        object IEntityStateProvider.Apply(object entity)
        {
            return ApplyDelegate(entity);
        }

        /// <summary>
        ///     Cancels a state of entity.
        /// </summary>
        /// <param name="entity">The specified entity.</param>
        /// <returns>An instance of object.</returns>
        object IEntityStateProvider.Cancel(object entity)
        {
            return CancelDelegate(entity);
        }

        /// <summary>
        ///     Gets a value indicating whether the entity has changes.
        /// </summary>
        bool IEntityStateProvider.HasChanges(object entity, string propertyName)
        {
            return HasChangesPropDelegate(entity, propertyName);
        }

        /// <summary>
        ///     Gets a value indicating whether the entity has changes.
        /// </summary>
        bool IEntityStateProvider.HasChanges(object entity)
        {
            return HasChangesDelegate(entity);
        }

        #endregion
    }
}